<template>
  <div class='recentlyPlayedSongList'>
    <div
      class="musicShowBlock"
      v-for="item in list"
      :key="item.resourceId"
      @click="jumpPage(item)"
    >
      <div class="musicImg">
        <img v-lazy="item.data.coverImgUrl + '?param=100y100'" width="100%">
      </div>
      <div class="musicIntroduce">
          <div
            class="musicName"
          >
            {{ item.data.name }}
          </div>
        <div class="title">
          <div
            class="musicAuthor"
          >
            by {{ item.data.creator.nickname }}
          </div>
          <div class="musicDuration">
            {{ item.playTime | relativeTime }}
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex'
import { getRecentlyPlayedSongList } from '@/api/user'

export default {
  name: 'recentlyPlayedSongList',
  components: {},
  props: {},
  data () {
    return {
      list: []
    }
  },
  computed: {
    ...mapState(['loginData'])
  },
  watch: {},
  created () {
    this.loadgGetSongList()
  },
  mounted () {},
  methods: {
    async loadgGetSongList () {
      const { data } = await getRecentlyPlayedSongList({
        cookie: this.loginData.cookie
      })
      this.list.push(...data.data.list)
      this.$emit('songListCount', this.list.length)
    },
    jumpPage (event) {
      this.$router.push({
        name: 'songList',
        params: {
          songListId: event.resourceId
        }
      })
    }
  }
}
</script>
<style lang='less' scoped>
.recentlyPlayedSongList {
  padding: 0 15px;
  .musicShowBlock {
    height: 60px;
    margin: 18px 0px;
    display: flex;
    overflow: hidden;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .musicImg {
      width: 60px;
      height: 60px;
      border-radius: 10px;
      background-color: #000;
      overflow: hidden;
      background-size: cover;
    }
    .musicIntroduce {
      width: 276px;
      .title {
        line-height: 30px;
        line-height: 25px;
        margin-left: 1px;
        display: flex;
        align-items: center;
        justify-content: space-between;
      }
      .musicName {
        line-height: 30px;
        font-size: 14px;
        font-weight: bold;
        color: #383838;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
      .musicAuthor {
        font-size: 12px;
        color: #acacac;
      }
      .musicDuration {
        text-align: right;
        width: 96px;
        font-size: 12px;
        color: #acacac;
      }
    }
  }
}
</style>
